package com.yonyou.cyxdms.basedata.service.controller.vehicleproduct;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyx.framework.service.excel.ExcelExportColumn;
import com.yonyou.cyx.framework.service.excel.ExcelGenerator;
import com.yonyou.cyxdms.basedata.service.constant.BasedataDictConstants;
import com.yonyou.cyxdms.basedata.service.dto.vehiclemodel.CarColorDTO;
import com.yonyou.cyxdms.basedata.service.dto.vehiclemodel.ColorImportDTO;
import com.yonyou.cyxdms.basedata.service.dto.vehiclemodel.ColorQueryDTO;
import com.yonyou.cyxdms.basedata.service.service.color.ColorService;
import com.yonyou.cyxdms.basedata.service.vo.ExportMsgVO;
import com.yonyou.cyxdms.basedata.service.vo.color.ExteriorAndInteriorColorVO;
import com.yonyou.cyxdms.basedata.service.vo.color.PageColorVO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 车辆颜色
 *
 * @author renwd
 * @since 2019/7/17
 */

@Api(value = "VehicleProductColorController", tags = "车辆颜色")
@RestController
@RequestMapping("/vehicleProduct/colors")
public class VehicleProductColorController {

    @Autowired
    private ColorService colorService;

    /**
     * 车辆颜色
     *
     * @param current
     * @param size
     * @param colorQueryDTO
     * @author Tansj
     * @since 2019/11/18
     */
    @ApiOperation(value = "车辆颜色", notes = "车辆颜色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    @GetMapping
    public IPage<PageColorVO> queryColor(@ApiParam(name = "pageNum", value = "当前页") @RequestParam("pageNum") Long current,
                                         @ApiParam(name = "limit", value = "分页大小") @RequestParam("limit") Long size,
                                         @Valid ColorQueryDTO colorQueryDTO) {
        Page<PageColorVO> page = new Page<>(current, size);
        return colorService.queryColor(page, colorQueryDTO);
    }

    /**
     * 修改颜色
     *
     * @param id
     * @param colorDTO
     * @return java.lang.Integer
     * @author renwd
     * @since 2019/7/17
     */
    @ApiOperation(value = "修改颜色", notes = "修改颜色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    @PutMapping("/{id}")
    public Integer updateColor(@PathVariable("id") Long id, @RequestBody CarColorDTO colorDTO) {
        return colorService.updateColor(id, colorDTO);
    }

    /**
     * 新增颜色
     *
     * @param colorDTO
     * @return java.lang.Integer
     * @author renwd
     * @since 2019/7/17
     */
    @ApiOperation(value = "新增颜色", notes = "新增颜色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    @PostMapping
    public Integer addColor(@RequestBody CarColorDTO colorDTO) {
        return colorService.addColor(colorDTO);
    }

    /**
     * 提供给下拉框车辆外饰
     *
     * @param
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.color.ExteriorAndInteriorColorVO>
     * @author renwd
     * @since 2019/7/18
     */
    @ApiOperation(value = "提供给下拉框车辆外饰", notes = "提供给下拉框车辆外饰")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    @GetMapping("/colorinfo/exterior")
    public List<ExteriorAndInteriorColorVO> selectExteriorColorInfo() {
        Map<String, Object> queryParam = new HashMap<>();
        queryParam.put("colorType", BasedataDictConstants.EXTERIOR_COLOR);
        return colorService.selectExteriorColorInfo(queryParam);
    }

    /**
     * 提供给下拉框车辆内饰
     *
     * @param
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.color.ExteriorAndInteriorColorVO>
     * @author renwd
     * @since 2019/7/18
     */
    @ApiOperation(value = "提供给下拉框车辆内饰", notes = "提供给下拉框车辆内饰")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    @GetMapping("/colorinfo/Interior")
    public List<ExteriorAndInteriorColorVO> selectInteriorColorInfo() {
        Map<String, Object> queryParam = new HashMap<>();
        queryParam.put("colorType", BasedataDictConstants.INTERIOR_COLOR);
        return colorService.selectExteriorColorInfo(queryParam);
    }

     /**
     * 颜色导入模板下载
     *
     * @return void
     * @author caozx
     * @since 2020/12/10
     */
    @ApiOperation(notes = "导出颜色模板", value = "导出颜色模板")
    @PostMapping(value = "/export")
        public void exportColorInfos(HttpServletResponse response) throws IOException {
        colorService.export(response);
    }

    /**
     * 颜色导入
     *
     * @return void
     * @author caozx
     * @since 2020/12/10
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    @PostMapping("/import")
    @ResponseBody
    @ApiOperation(value = "批量导入", notes = "批量导入", httpMethod = "POST")
    public Map<String,List<ExportMsgVO>> upload(@RequestParam("file") MultipartFile file) {
        return colorService.upload(file);
    }
}
